package com.thyme.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashSet;
import java.util.Set;

/**
 * @author thyme
 * @ClassName Person
 * @Description TODO
 * @Date 2020/6/12 15:14
 */
@NodeEntity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Person {

    @Id
    @GeneratedValue
    private Long id;

    private String name;

    private String born;

    public Person(String name, String born) {
        this.name = name;
        this.born = born;
    }

    @Relationship(type = "ACTED_IN",direction = Relationship.OUTGOING)
    public Set<Movie> actors;

    public void addActor(Movie movie) {
        if (actors == null) {
            actors = new HashSet<Movie>();
        }
        actors.add(movie);
    }

    @Relationship(type = "DIRECTED", direction = Relationship.OUTGOING)
    public Set<Movie> directors;

    public void addDirector(Movie movie) {
        if (directors == null) {
            directors = new HashSet<Movie>();
        }
        directors.add(movie);
    }



}
